namespace Billing
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.IO;

    public class HttpGetBillReport : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["BUID"] == null)
            {
                base.Response.Redirect("default.aspx",true);
            }
            if ((base.Request.QueryString["ID"] != null) && (base.Request.QueryString["DownloadID"] != null))
            {
                DataTable dt_temp = new ClsBillReportRepository { ID = Convert.ToInt64(base.Request.QueryString["ID"].ToString()), DownloadID = base.Request.QueryString["DownloadID"].ToString() }.SelectByIDDownloadID();
                if ((dt_temp != null) && (dt_temp.Rows.Count > 0))
                {
                    byte[] imagecontent = (byte[]) dt_temp.Rows[0]["ReportData"];
                    //byte[] imagecontent = new byte[0];
                    //string filename = Server.MapPath("/") + "temp/" + dt_temp.Rows[0]["ReportFileName"].ToString();
                    //using (FileStream fs = new FileStream(filename, FileMode.Open))
                    //{
                    //    imagecontent = new byte[fs.Length];
                    //    fs.Read(imagecontent, 0, imagecontent.Length);
                    //}
                    base.Response.ContentType = dt_temp.Rows[0]["ContentType"].ToString();
                    base.Response.AddHeader("Content-Disposition", "attachment;filename=" + dt_temp.Rows[0]["ReportFileName"].ToString());
                    this.Context.Response.BinaryWrite(imagecontent);
                }
            }
        }
    }
}
